/**
 * 
 * ***/
package Avocado.visual {
	import flash.display.MovieClip;
	import flash.events.Event;
	
	public class PhotoNavigator extends MovieClip {
		
		private var photos:Array;
		private var movies:Array;
		
		private var active:MovieClip;
		
		public function PhotoNavigator(_photos:Array) {
			super();
			this.photos = _photos;
			this.addEventListener(Event.ADDED_TO_STAGE, initThis);
		}
		
		private function initThis(e:Event):void{
			this.removeEventListener(Event.ADDED_TO_STAGE, initThis);

			movies = new Array;
			
			for (var f:* in photos){
				var tmp:SpriteImage = new SpriteImage(photos[f], 0);
				tmp.addEventListener(Event.COMPLETE, tmpComplete);
				movies.push(tmp);
			}
		}
		
		public function updateThis(e:Event=null):void{
			var fac:Number = new Number(1);
			if (active) {
				if ( (stage.stageWidth / active.width) < (stage.stageHeight / active.height) ) {
					fac = (stage.stageHeight / active.height);
				} else {
					fac = (stage.stageWidth / active.width);
				}
			}
			
			this.scaleX = fac;
			this.scaleY = fac;
		}
		
		
		
		
		
		private function tmpComplete(e:Event):void{
			trace(e);
			e.currentTarget.removeEventListener(Event.COMPLETE, tmpComplete);

			firstPictureComplete();
		}
		
		private function firstPictureComplete():void{
			active = MovieClip(movies[0]);
			active.x = -active.width/2;
			active.y = -active.height/2;
			addChild(active);
			
			updateThis();
		}
		
		
	}
}